from os.path import exists, join
import shutil
import auto_utility
import auto_log
import lib
if not exists(join(lib.PATH_ROOT, 'config.txt')):
    lib.parse_data_data()
    lib.create_config(join(lib.PATH_ROOT, 'diskpart_command.xml'), '4')
    lib.set_count('0')
    if lib.file_create(join(lib.PATH_ROOT, 'config.txt')) == -1:
        print('error at create config')
        exit(-1)
file_task = lib.parse_task_name()
task = file_task.split('_')[0]
dest = file_task.split('_')[-1]
script_num = lib.get_count()
if task == 'base':
    if script_num == '0':
        f1 = lib.fg_generate_by_size('',r"'e:\data\base'","'*.txt'","100m", "1m", "10m")
        f2 = lib.fsum_create_md5('',lib.PATH_TO_DATA)
        f3 = lib.inc_count()
        exit(0)
    if script_num == '1':
        if exists(lib.PATH_TO_DATA):
            shutil.rmtree(lib.PATH_TO_DATA)
        exit(0)
elif task == 'inc':
    if script_num == '0':
        f1 = lib.fg_generate_by_size('',r"'e:\data\base'","'*.txt'","100m", "1m", "10m")
        f2 = lib.inc_count()
        exit(0)
    if script_num == '1':
        f1 = lib.fg_generate_by_size('',r"'e:\data\inc'","'*.txt'","100m", "1m", "10m")
        f2 = lib.fsum_create_md5('',lib.PATH_TO_DATA)
        f3 = lib.inc_count()
        exit(0)
elif task == 'compl':
    if script_num == '0':
        f1 = lib.fg_generate_by_size('',r"'e:\data\base'","'*.txt'","100m", "1m", "10m")
        f2 = lib.inc_count()
        exit(0)
    if script_num == '1':
        f1 = lib.fg_generate_by_size('',r"'e:\data\compl'","'*.txt'","100m", "1m", "10m")
        f2 = lib.fsum_create_md5('',lib.PATH_TO_DATA)
        f3 = lib.inc_count()
        exit(0)
if script_num == '2':
        if exists(lib.PATH_TO_DATA):
            shutil.rmtree(lib.PATH_TO_DATA)
        if dest == 'NTFS':
            lib.create_config(join(lib.PATH_ROOT, 'diskpart_command.xml'), '6')
            if lib.change_dest_in_txt_for_UFSD() == -1:
                print('error at change destination in txt')
                exit(-1)
            else:
                lib.create_config(join(lib.PATH_ROOT, 'diskpart_command.xml'), '5')
        else:
            if lib.change_dest_in_txt() == -1:
                print('error at restore, can not change dest in txt')
                exit(-1)
        exit(0)
exit(0)